import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
   state :{
       username:"游客",
       isadmin: false
   },

    //这个相当于set方法
    mutations: {
        updateUser(state, username) {
            state.username = username;
        },

        isadmin(state,flag) {
            state.isadmin = flag;
        }
    },

    //这个是异步的set方法
    actions: {
        asyncUpdateUser(context, username) {
            context.commit('updateUser', username);
        },

        asyncIsadmin(context, flag) {
            context.commit('isadmin',flag);
        }
    },
})


export default store
